package com.lp.user.service.impl;

import com.lp.common.Result;
import com.lp.common.base.BaseService;
import com.lp.common.dto.PageBase;
import com.lp.user.dao.AdminMapper;
import com.lp.user.dao.UserMapper;
import com.lp.user.dto.Admin;
import com.lp.user.dto.User;
import com.lp.user.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("adminService")
public class AdminServiceImpl extends BaseService implements AdminService {

    @Autowired
    private AdminMapper adminMapper;


    public Result getPage(Integer currentPage){
        Result r=new Result();
        PageBase<Admin> dt=new PageBase<Admin>();
        dt.setCurrentPage(currentPage);
        Map p=new HashMap();
        p.put("startIndex",dt.getStartIndex());
        p.put("pageSize",10);
        int count=adminMapper.getCount(p);
        List<Admin> u= adminMapper.getPageByParam(p);
        dt.setData(u);
        dt.setCount(count);
        r.setData(dt);
        return r;
    }

    @Override
    public Result saveAdminInfor(Admin dt) {
        int i = saveAdminInfo(dt);
        Result r = new Result();
        if (i == 0) {
            r.setSuccess(SUCCESS);
        } else {
            r.setSuccess(FAIL);
        }
        r.setData(dt);
        return r;
    }

    @Override
    public Result updateAdminInfo(Admin dt) {
        Result r = new Result();
        int i = adminMapper.updateByPrimaryKeySelective(dt);
        if (i > 0) {
            r.setSuccess(SUCCESS);
        } else {
            r.setSuccess(FAIL);
        }
        return r;
    }

    @Override
    public int saveAdminInfo(Admin dt) {
        return adminMapper.insertSelective(dt);
    }
}
